var apiLogIds = new Array();
var currentPageIndex;// 当前页码数
var currentCount;// 当前总数
var chooseDeleteCount = 0;
layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

	//接口日志列表
    var tableIns = table.render({
      elem: '#sysApiLog_table'
      ,toolbar: '#toolbarApilog'
      ,url:request("/console/ApiLogList")+"&userId=1000"
      ,id: 'sysApiLogs_table'
      ,page: true
      ,curr: 0
      ,limit:Common.limit
      ,limits:Common.limits
      ,groups: 7
      ,cols: [[ //表头
            {field: 'userId', title: '操作者',width:'6%',templet: function(d){
                    return "系统管理员"
                }}
           ,{field: 'apiId', title: '接口Id',width:'11%'}
           ,{field: 'totalTime', title: '耗时(毫秒)',sort: true, width:'8%'}
           ,{field: 'time',title:'调用时间',sort: true, width:'11%',templet: function(d){
          		// return Common.formatDate(d.time,"yyyy-MM-dd hh:mm:ss");
          		return UI.getLocalTime(d.time);
          }}
          ,{field: 'fullUri', title: '完整url', width:'20%'}
          ,{field: 'clientIp', title: '调用端ip',sort: true, width:'11%'}
          ,{field: 'userAgent', title: '调用端信息',sort: true, width:'11%'}
          ,{field: 'stackTrace', title: '错误信息',sort: true, width:'11%'}
          ,{fixed: 'right', title:"操作", align:'left', toolbar: '#sysApiLog_Bar'}
        ]]
		,done:function(res, curr, count){
      checkRequst(res);
            //权限判断
            var arr=['apilog-delete'];
            manage.authButton(arr);

			$(".group_name").val("");
			if(localStorage.getItem("role")==1){
                $(".checkDeleteUsersFriends").hide();
                $(".del").remove();
                $(".deleteSevenDaysAgoLogs").hide();
		    }
            var pageIndex = tableIns.config.page.curr;//获取当前页码
            var resCount = res.count;//获取table总条数
            currentCount = resCount;
            currentPageIndex = pageIndex;
		}
  });

    //监听表格复选框选择
    table.on('checkbox(sysApiLog_table)', function(obj){
        if (obj.type == 'one'){
            chooseDeleteCount = obj.checked == true ? chooseDeleteCount + 1 : chooseDeleteCount - 1;
        }else if (obj.type == 'all') {
            chooseDeleteCount = obj.checked == true ? $(".layui-laypage-limits").find("option:selected").val() : 0;
        }
        $(".chooseDeleteCount").html("已选择 "+chooseDeleteCount+" 项");
        chooseDeleteCount < 1 ? $(".mustDelete").hide() :$(".mustDelete").show();
    });


  //列表操作
  table.on('tool(sysApiLogs_table)', function(obj){
      var layEvent = obj.event,
          data = obj.data;
          console.log("apiLogId ======>>> "+data.id);
      if(layEvent === 'del'){ //删除
          ApiLog.toolbarApilogImpl(data.id,1);
      }

  });

})
var ApiLog = {
    toolbarApilog:function () {
        // 多选操作
        var checkStatus = layui.table.checkStatus('sysApiLogs_table'); //idTest 即为基础参数 id 对应的值
        
        for (var i = 0; i < checkStatus.data.length; i++){
            apiLogIds.push(checkStatus.data[i].id);
        }
        if(0 == checkStatus.data.length){
            layer.msg("请勾选要删除的行");
            return;
        }
        console.log(apiLogIds);
        ApiLog.toolbarApilogImpl(apiLogIds.join(","),checkStatus.data.length);
    },
    toolbarApilogImpl:function (apiLogId,checkLength) {
        layer.confirm('确定删除指定的日志记录',{icon:3, title:'提示消息',skin : "layui-ext-motif",yes:function () {
                Common.invoke({
                    url:request('/console/delApiLog'),
                    data:{
                        apiLogId :apiLogId,
                    },
                    success:function(result){
                        if(result.resultCode==1){
                            layer.msg("删除成功",{"icon":1});
                            apiLogIds = [];
                            // layui.table.reload("sysApiLogs_table");
                            Common.tableReload(currentCount,currentPageIndex,checkLength,"sysApiLogs_table");
                        }
                    }
                })
            },btn2:function () {
                apiLogIds = [];
            },cancel:function () {
                apiLogIds = [];
            }});
    }

}
$(function () {
    //调用父级页面的Js函数
    window.parent.getJointVisitPath();
})

	
	
